package com.android.qjpmc.application_module.splash;

import android.text.TextUtils;

import com.android.qjpmc.BuildConfig;
import com.android.qjpmc.R;
import com.android.qjpmc.data_module.CUserModule;
import com.android.qjpmc.data_module.PwrDataModule;
import com.android.qjpmc.manager.IntentManager;
import com.android.qjpmc.widget.base.BaseCommonActivity;
import com.android.qjpmc.widget.manager.SPManager;
import com.android.qjpmc.widget.retrofithelper.http.Url;
import com.android.qjpmc.widget.retrofithelper.rxsubscriber.CommonObserver;
import com.android.qjpmc.widget.utils.TimerUtils;
import com.gyf.immersionbar.BarHide;
import com.gyf.immersionbar.ImmersionBar;
import com.orhanobut.logger.Logger;


public class SplashActivity extends BaseCommonActivity {

    @Override
    public int getLayoutId() {
        return R.layout.activity_splash;
    }

    @Override
    public void initView() {
        super.initView();
        String baseUrl = SPManager.BaseUrlConfigData.getBaseUrl(this);
        Logger.d("baseUrl"+baseUrl);
        Url.BASE_URL = TextUtils.isEmpty(baseUrl) ? BuildConfig.BASE_URL : baseUrl;

        ImmersionBar.with(this).fullScreen(true).statusBarDarkFont(true, 0.2f).hideBar(BarHide.FLAG_HIDE_NAVIGATION_BAR).init();
        String loginInfo = SPManager.LoginInfo.getLoginInfo();

        String PathName = this.getApplicationContext().getFilesDir() + "";
        PwrDataModule.getInstance().SetBasePath(PathName);

        PwrDataModule.getInstance().initData();
        TimerUtils.countdown(1).
                subscribe(new CommonObserver<Integer>() {
                    @Override
                    public void onComplete() {
                        super.onComplete();
                        if (TextUtils.isEmpty(loginInfo)) {
                            IntentManager.toLoginActivity(SplashActivity.this);
                        } else {
                            CUserModule module = PwrDataModule.getInstance().GetUserModule();
                            if (module == null) {

                            } else {
                                module.SetCurrentUserName(loginInfo);
                            }

                            IntentManager.toHomeActivity(SplashActivity.this);
                        }
                        finish();
                    }
                });


    }

    @Override
    protected boolean isNeedLoadStatusBar() {
        return false;
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
    }

    @Override
    public void onBackPressed() {

    }
}
